package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.NewProductHome;
import com.wteam.dragon.shop.service.NewProductHomeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 陈晓辉
 * @Date 2021/3/25 20:55
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "新品推荐管理")
@RequestMapping("newProductHome")
public class NewProductHomeController {
    private final NewProductHomeService newProductHomeService;

    @Log("批量添加商品到新品推荐")
    @ApiOperation("批量添加商品到新品推荐")
    @PostMapping("addNewProductHome")
    @PreAuthorize("@el.check('addNewProductHome')")
    public ResultMessage addNewProductHome(@RequestParam List<Long> ids){
        return newProductHomeService.addNewProductHome(ids);
    }

    @Log("批量删除新品推荐")
    @ApiOperation("批量删除新品推荐")
    @DeleteMapping("delNewProductHome")
    @PreAuthorize("@el.check('delNewProductHome')")
    public ResultMessage delNewProductHome(@RequestParam List<Long> ids){
        return newProductHomeService.delNewProductHome(ids);
    }

    @Log("更改排序")
    @ApiOperation("更改排序")
    @PutMapping("editNewProductHome")
    @PreAuthorize("@el.check('editNewProductHome')")
    public ResultMessage editNewProductHome(Long id, Long sort){
        return newProductHomeService.editNewProductHome(id, sort);
    }

    @Log("分页获得新品推荐")
    @ApiOperation("分页获得新品推荐")
    @PutMapping("pageNewProductHome")
    @PreAuthorize("@el.check('pageNewProductHome')")
    public ResultMessage pageNewProductHome(PageVo<NewProductHome> pageVo, String productName, String recommendStatus){
        Page<NewProductHome> page = BeanUtil.fromPage(pageVo);
        return newProductHomeService.pageNewProductHome(page, productName, recommendStatus);
    }

    @Log("批量推荐和批量取消推荐")
    @ApiOperation("批量推荐和批量取消推荐")
    @PutMapping("editNewProductHomeStatus")
    @PreAuthorize("@el.check('editNewProductHomeStatus')")
    public ResultMessage editNewProductHomeStatus(@RequestParam List<Long> ids, Integer status){
        return newProductHomeService.editNewProductHomeStatus(ids, status);
    }

}
